const { remm } = require('./src/mock')
const bodyParser = require('body-parser')
const userList = [{
  username: 'admin',
  password: '123456'
},{
  username: '1906A',
  password: '42'
}]
module.exports = {
  devServer: {
    before(app) {
      app.use(bodyParser.json())
      app.get('/remm', (req, res) => {
        res.send({
          code: 200,
          data: remm
        })
      })


      app.post('/post/detail', (req, res) => {
        const { id } = req.body
        const item = remm.find(item => item.id === id)
        res.send({
          code: 200,
          data: item
        })
      }) 

      app.post('/api/login', (req, res) => {
        const { username, password } = req.body;
        const isExit = userList.find(item => item.username === username && item.password === password)

        if(isExit) {
          res.send({
            code: 200,
            token: username
          })
        } else {
          res.send({
            code: 404,
          })
        }
      })
    }
  }
  
}